import {Controller, Get, Post, Body, Patch, Param, Delete, Request} from '@nestjs/common';
import {AuthService} from './auth.service';
import {CreateAuthDto} from './dto/create-auth.dto';
import {UpdateAuthDto} from './dto/update-auth.dto';

@Controller('auth')
export class AuthController {
    constructor(private readonly authService: AuthService) {
    }

    // 提供接口让客户端获取 CSRF 令牌
    @Get('csrf-token')
    getCsrfToken(@Request() req) {
        // 生成令牌（会自动设置到 Cookie 中，基于步骤 2 的配置）
        const csrfToken = req.csrfToken();
        return {csrfToken}; // 返回令牌给客户端
    }

    @Post()
    create(@Body() createAuthDto: CreateAuthDto) {
        return this.authService.create(createAuthDto);
    }

    @Get()
    findAll() {
        return 11111;
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.authService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateAuthDto: UpdateAuthDto) {
        return this.authService.update(+id, updateAuthDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.authService.remove(+id);
    }
}
